//
//  MNDDownLoadFile.m
//  minidai
//
//  Created by Vitas on 2018/7/10.
//  Copyright © 2018年 迷你金服. All rights reserved.
//

#import "MNDDownLoadFile.h"

@implementation MNDDownLoadFile

+ (void)downLoadFileWithUrl:(NSString *)url isArea:(BOOL)isArea {
    
    [APIManager sendRequestWithURL:url parameters:[MNDSign signedParam] method:kXMHTTPMethodGET onSuccess:^(ResponseModel *responseModel) {
        if (responseModel.status == ResponseSuccess) {
            NSString *oldVersion = [UserDefaultsTool objectForKey:isArea ? kDownLoadAddressVersion : kDownloadCarModelVersion];
            NSDictionary *urlDict = responseModel.data;
            NSString *urlStr = [urlDict objectForKey:@"url"];
            NSString *version = [urlDict objectForKey:@"version"];
            if ([oldVersion isEqualToString:version]) {
                NSLog(@"版本%@",version);
            }else {
                [UserDefaultsTool saveObject:version forKey:isArea ? kDownLoadAddressVersion : kDownloadCarModelVersion];
                [APIManager downloadWithUrl:urlStr onProgress:^(NSProgress *progress) {
                    
                } onSuccess:^(ResponseModel *response) {
                    NSLog(@"下载成功");
                } onFailure:^(NSError *error) {
                    
                } onFinish:^(id responseObj, NSError *error) {
                    
                }];
            }
            
        }
    } onFailure:^(NSError *error) {
        [NetworkProgressHUD showHudNetworkError:error];
    }];
}

@end
